﻿@model KL.Store.Web.Models.ProductsModel
@using KL.Store.Core;
@if (Model != null && Model.RelatedProducts != null && Model.RelatedProducts.Count > 0)
{
    var relPosition = ViewBag.RelatedPosition;
    var itemCounter = 1;
    var columnCount = 4;
    var cssColumnClass = "col-xs-6 col-sm-6 col-md-4 col-lg-3";
    var listImageType = "_w";
    var addToCartButtonStyle = 1;
    if (Parameters.Theme == "DK")
    {
        addToCartButtonStyle = 2;
    }
    if (!string.IsNullOrEmpty(Model.ListImageType))
    {
        listImageType = Model.ListImageType;
    }
    var cssColumnClassOthers = "";
    if (relPosition == "bottom")
    {
        cssColumnClassOthers = "col-xs-6 col-sm-4 col-md-3 col-lg-2";
    }
    else if (relPosition == "bottomright")
    {
        cssColumnClassOthers = "col-xs-12 col-sm-12 col-md-4 col-lg-3";
    }
    else if (relPosition == "left")
    {
        cssColumnClassOthers = "col-xs-12 col-sm-12 col-md-12 col-lg-12";
    }
    if (Parameters.Theme == "HA")
    {
    <div class="category-main-title">
        <span><b>@Model.CategoryName</b> kategorisinden benzer ürünler</span>
    </div>
    <div class="products s@(columnCount)@(listImageType)" id="products@(Model.CategoryId)">
        <ul>
            @foreach (var item in Model.RelatedProducts)
            {
                var inLastColumn = "";
                if (columnCount != 0 && itemCounter % columnCount == 0)
                {
                    inLastColumn = "inLastColumn";
                }
                else
                {
                    inLastColumn = "";
                }

                <li class="productLi @cssColumnClass @inLastColumn">
                    <div class="product-outer">
                        <div class="product-inner">
                            <div class="product-image">
                                <a id="pr_@item.ProductId" class="prdLink" href="@item.LinkUrl" title="@(item.ProductName.Replace("\"", ""))">
                                    @if (item.ProductImageCount > 0)
                                    {
                                        <img id="ip_@item.ProductId" src="@(Parameters.WebSiteImageUrl)/product-medium/@(item.ProductId)_1@(listImageType).jpg" alt="@(item.ProductName.Replace("\"", ""))" />  
                                    }
                                    else
                                    {
                                        <img id="ip_@item.ProductId" src="/Images/@Parameters.Theme/product-image-not-found-200x.jpg" alt="@(item.ProductName.Replace("\"", ""))" />
                                    }
                                </a>
                                <a class="incele" href="@item.LinkUrl" title="@(item.ProductName.Replace("\"", ""))">İncele</a>
                                @if (!item.CheckStock || Parameters.AllowEndedProducts || item.InStockDepo > 0)
                                {
                                    <a href="@item.LinkUrl">
                                        @if (Parameters.Theme == "HA")
                                        {
                                            var bottomAbsolute = 10;
                                            if (!string.IsNullOrEmpty(item.SpecialText))
                                            {
                                            <div class="productprop prop_specialtext hidden-xs hidden-sm" style="bottom: @(bottomAbsolute)px;">
                                                <div class="prop_content">
                                                    <div class="prop_text">
                                                        <span>@item.SpecialText</span>
                                                    </div>
                                                </div>
                                            </div>
                                                bottomAbsolute += 31;
                                            }
                                            if (item.FastCargo)
                                            {
                                                var fastStr = "1-3 Gün Kargo";
                                                if (item.InStockDepo >= Parameters.MinInStockAmountForFastCargo && Parameters.MinInStockAmountForFastCargo != 0)
                                                {
                                                    fastStr = "24 Saatte Kargo";
                                                }
                                            <div class="productprop prop_24h" style="bottom: @(bottomAbsolute)px;">
                                                <div class="prop_content">
                                                    <div class="prop_icon"></div>
                                                    <div class="prop_text">
                                                        <div class="prop_text_left"></div>
                                                        <span>@fastStr</span>
                                                    </div>
                                                </div>
                                            </div>
                                                bottomAbsolute += 35;
                                            }
                                            else if (item.InStockDepo >= Parameters.MinInStockAmountForFastCargo && Parameters.MinInStockAmountForFastCargo != 0)
                                            {
                                            <div class="productprop prop_24h" style="bottom: @(bottomAbsolute)px;">
                                                <div class="prop_content">
                                                    <div class="prop_icon"></div>
                                                    <div class="prop_text">
                                                        <div class="prop_text_left"></div>
                                                        <span>24 Saatte Kargo</span>
                                                    </div>
                                                </div>
                                            </div>
                                                bottomAbsolute += 35;
                                            }
                                            else if (item.DeliveryPeriod == "Gün" && item.DeliveryTime <= Parameters.MinDeliveryTimeForFastCargo && item.DeliveryTime > 0)
                                            {
                                            <div class="productprop prop_24h" style="bottom: @(bottomAbsolute)px;">
                                                <div class="prop_content">
                                                    <div class="prop_icon"></div>
                                                    <div class="prop_text">
                                                        <div class="prop_text_left"></div>
                                                        <span>Hızlı Kargo</span>
                                                    </div>
                                                </div>
                                            </div>
                                                bottomAbsolute += 35;
                                            }

                                            if (item.FreeCargo)
                                            {
                                            <div class="productprop prop_free" style="bottom: @(bottomAbsolute)px;">
                                                <div class="prop_content">
                                                    <div class="prop_icon"></div>
                                                    <div class="prop_text">
                                                        <div class="prop_text_left"></div>
                                                        <span>Ücretsiz Kargo</span>
                                                    </div>
                                                </div>
                                            </div>
                                                bottomAbsolute += 35;
                                            }
                                            if (item.OpportunityProduct)
                                            {
                                            <div class="productprop prop_oppoturnity" style="bottom: @(bottomAbsolute)px;">
                                                <div class="prop_content">
                                                    <div class="prop_icon"></div>
                                                    <div class="prop_text">
                                                        <div class="prop_text_left"></div>
                                                        <span>Fırsat Ürünü</span>
                                                    </div>
                                                </div>
                                            </div>
                                                bottomAbsolute += 35;
                                            }
                                            if (!string.IsNullOrEmpty(item.GiftString))
                                            {
                                            <div class="productprop prop_gift" style="bottom: @(bottomAbsolute)px;">
                                                <div class="prop_content">
                                                    <div class="prop_icon"></div>
                                                    <div class="prop_text">
                                                        <div class="prop_text_left"></div>
                                                        <span>@item.GiftString</span>
                                                    </div>
                                                </div>
                                            </div>
                                            }
                                            if (item.NewProduct)
                                            {
                                            <div class="prop_new"></div>
                                            }
                                            if (item.DiscountPercent > 0)
                                            {
                                            <div class="prop_discountPercent discountView2"><span>%</span>@Convert.ToInt32(item.DiscountPercent)<span class="dsccls">İNDİRİM</span></div>
                                            }
                                            else if (item.DiscountTotal > 0)
                                            {
                                            <div class="prop_discountPercent discountView2">@Convert.ToInt32(item.DiscountTotal)@Html.Raw(item.Currency == "TL" ? "<i class=\"fa fa-try\"></i>" : " " + item.Currency)<span class="dsccls">İNDİRİM</span></div>                                        
                                            }
                                            else if (item.DiscountDisplayTotal > 0)
                                            {
                                            <div class="prop_discountPercent discountView2"><span>%</span>@Convert.ToInt32(item.DiscountDisplayTotal)<span class="dsccls">İNDİRİM</span></div>                                    
                                            }
                                        }
                                    </a>
                                }
                            </div>
                            <a class="hizliBak" href="#quickViewContainer" title="@(item.ProductName.Replace("\"", ""))" data-id="@item.ProductId" data-name="@item.ProductName" data-prcode="@item.ProductCode" data-imgcount="@item.ProductImageCount"></a>
                            <div class="product-title">
                                <a id="pl_@item.ProductId" class="prdLink" href="@item.LinkUrl">@(item.ProductName)</a>
                            </div>
                            <div class="product-price">
                                @{
                                var priceFilterStr = "###,###,##0.00";
                                if (Parameters.HideOddFromPrice)
                                {
                                    priceFilterStr = "###,###,##0";
                                }
                                var productOldPrice = item.OldPrice > 0 ? @item.OldPrice.ToString("###,###,##0") : "";
                                var productNewPrice = "";
                                var productExchangePrice = "";
                                decimal productNewPriceNumber = 0;
                                var productSecondPrice = "";
                                        
                                }
                                @if (Parameters.ShowExchangePricesWithoutTax && item.ExchangePrice > 0)
                                {
                                    productExchangePrice = item.ExchangePrice.ToString(priceFilterStr) + " " + item.ExchangeCurrency + " <span class=\"taxinc\">+KDV</span>";
                                }
                                @if (Parameters.ShowPricesWithoutTax && item.SpecialPriceWithOutTax > 0)
                                {
                                    productNewPrice = (Parameters.HideOddFromPrice ? decimal.Ceiling(item.SpecialPriceWithOutTax) : item.SpecialPriceWithOutTax).ToString(priceFilterStr) + " " + item.Currency + " <span class=\"taxinc\">+KDV</span>";
                                    productNewPriceNumber = item.SpecialPriceWithOutTax;
                                }
                                else if (Parameters.ShowPricesWithoutTax && item.SpecialPriceWithOutTax <= 0)
                                {
                                    productNewPrice = (Parameters.HideOddFromPrice ? decimal.Ceiling(item.PriceWithOutTax) : item.PriceWithOutTax).ToString(priceFilterStr) + " " + item.Currency + " </span><span class=\"taxinc\">+KDV</span>";
                                    productNewPriceNumber = item.PriceWithOutTax;
                                }
                                else if (!Parameters.ShowPricesWithoutTax && item.SpecialPrice > 0)
                                {
                                    productNewPrice = (Parameters.HideOddFromPrice ? decimal.Ceiling(item.SpecialPrice) : item.SpecialPrice).ToString(priceFilterStr) + " " + item.Currency;
                                    productNewPriceNumber = item.SpecialPrice;
                                }
                                else if (!Parameters.ShowPricesWithoutTax && item.SpecialPrice <= 0)
                                {
                                    productNewPrice = (Parameters.HideOddFromPrice ? decimal.Ceiling(item.Price) : item.Price).ToString(priceFilterStr) + " " + item.Currency;
                                    productNewPriceNumber = item.Price;
                                }
                                @{
                                var rate = (item.CampaignProduct && Model.CampaignVoucherRate > 0) ? Model.CampaignVoucherRate : Model.VoucherRate;
                                if (rate > 0 && !(Parameters.OnlyUseCCandMTforOpportunityProduct && item.OpportunityProduct))
                                {
                                    productSecondPrice = ((productNewPriceNumber * rate) / (Parameters.ShowVoucherPricesWithInstallment ? Parameters.SenetTaksit1 : 1)).ToString(priceFilterStr) + " " + item.Currency;
                                }
                                }
                                <a href="@item.LinkUrl" class="sale">@if (!item.CheckStock || Parameters.AllowEndedProducts || item.InStockDepo > 0)
                                                                     {
                                                                            
                                    <div class="product-price-section">
                                        @{
                                            <span class="productNewPriceStr productPrice">@Html.Raw(productNewPrice)</span>
                                                                         if (!string.IsNullOrEmpty(productExchangePrice))
                                                                         {
                                            <span class="productNewPriceStr productPrice">@Html.Raw(productExchangePrice)</span><br />
                                                                         }
                                                                         if (productSecondPrice != "")
                                                                         {
                                            <span class="productSecondPriceStr"><span class="senetliAyda">@(Parameters.ShowVoucherPricesWithInstallment ? "ayda " : "")</span>@Html.Raw(productSecondPrice)</span>
                                                                         }
                                        }
                                    </div>
                                    
                                                                         if (productSecondPrice != "")
                                                                         {
                                    <div class="product-price-section">
                                        <span class="fiyatAciklama"><span class="fiyatAciklamaSolCizgi">- </span>Kredi Kartı<span class="fiyatAciklamaSagCizgi"> - </span></span>
                                        <span class="fiyatAciklama"><span class="fiyatAciklamaSolCizgi">- </span>Senetli<span class="fiyatAciklamaSagCizgi"> - </span></span>
                                    </div>
                                                                         }
                                                                         if (productOldPrice != "")
                                                                         {
                                    <span class="sale-original">@productOldPrice @item.Currency</span>
                                                                         }
                                                                         else if (item.DiscountDisplayTotal > 0)
                                                                         {
                                                                             var indirimGoster = ((Decimal.Parse(productNewPrice.Replace(" TL", "")) / (100 - item.DiscountDisplayTotal)) * 100);
                                    <span class="sale-original">@indirimGoster.ToString("###,###,##0") @item.Currency</span>
                                                                         }
                                                                         else if (item.MarketPrice > 0)
                                                                         {
                                    <span class="sale-original">@item.MarketPrice.ToString("###,###,##0") @item.Currency</span>
                                                                         }
                                                                     }
                                                                     else
                                                                     {
                                    <span style="font-weight: normal;">Tükendi</span>   
                                                                     }
                                </a>
                            </div>
                            @if (Parameters.UseWishList)
                            {
                                <div class="toList">
                                    <a id="prd_@item.ProductId" onclick="addToWishList('@(item.ProductId)');" >
                                        <img
                                src="/Images/@(Parameters.Theme)/ToList.jpg" title="Listeme Ekle" alt="Listeme Ekle" style="width: 35px;
                                height: 35px; vertical-align: middle;margin-top:5px" /></a>
                                </div>
                            }
                            @if (!item.CheckStock || Parameters.AllowEndedProducts || item.InStockDepo > 0)
                            {
                                if (addToCartButtonStyle == 2)
                                {<div class="toCart">
                                    <a id="cart_@item.ProductId" @{if (item.InstallmentNeeded)
                                                                   { <text>href="@item.LinkUrl"</text> }
                                                                   else
                                                                   { <text>class="addToCart"</text> }} >
                                        <button class="button-alt">Sepete Ekle</button>
                                    </a>
                                </div>
                                }
                                else
                                {
                                <div class="toCart">
                                    <a id="cart_@item.ProductId" @{if (item.InstallmentNeeded)
                                                                   { <text>href="@item.LinkUrl"</text> }
                                                                   else
                                                                   { <text>class="addToCart"</text> }} title="Sepete Ekle">
                                        <img src="/Images/@(Parameters.Theme)/urun-hover-sepet.png" alt="Sepete Ekle" />
                                    </a>
                                </div>
                                    
                                }
                            }
                        </div>
                    </div>
                </li>
                            if (itemCounter % columnCount == 0 && itemCounter <= Model.RelatedProducts.Count() - 1)
                            {
                @Html.Raw("</ul><ul>");
                            }
                            itemCounter++;
            }
        </ul>
    </div>
            if (Model.RelatedProducts.Count() > columnCount)
            {
    <script type="text/javascript">
        $(document).ready(function ()
        {
            if ($(document).width() > 999)
            {
                $("#products@(Model.CategoryId)").slidesjs({
                    width: 1000,
                    @{
                if (columnCount == 6)
                {
                        <text>height: 175,</text>
                }
                else if (columnCount == 4)
                {
                        <text>height: 205,</text>
                }
                else if (columnCount == 3)
                {
                        <text>height: 260,</text>
                }
                    }
                    pagination: {
                        active: false
                    },
                    navigation: {
                        active: true,
                        effect: "slide"
                    },
                    play: {
                        active: false,
                        effect: "slide",
                        interval: 5000,
                        auto: true,
                        swap: false,
                        pauseOnHover: true,
                        restartDelay: 4500
                    },
                    pauseOnHover: true
                }).addClass("itWithSlider");
                $("a.slidesjs-navigation").html("");
            }
        });
    </script>
            }
    }
    else
    {
    <div class="related-products">
        <div class="related-products-row">
            <div class="related-products-inner">
                <div class="related-products-content">
                    <div class="related-section">
                        <ul>
                            @{var relatedProductCount = 1;}
                            @foreach (var item in Model.RelatedProducts)
                            {
                                <li class="@(cssColumnClassOthers)">
                                    <div class="related-outer">
                                        <div class="related-inner">
                                            <a class="hizliBak" href="#quickViewContainer" title="@(item.ProductName.Replace("\"", ""))" data-id="@item.ProductId" data-name="@item.ProductName" data-prcode="@item.ProductCode" data-imgcount="@item.ProductImageCount">
                                                @if (item.ProductImageCount > 0)
                                                {
                                                    <img src="@(Parameters.WebSiteImageUrl)/product-medium/@(item.ProductId)_1_s.jpg" />                                            
                                                }
                                                else
                                                {
                                                    <img src="/Images/@Parameters.Theme/product-image-not-found-200x.jpg" />
                                                }
                                                @if (relPosition != "bottomright")
                                                {
                                                    <p class="product-name">@item.ProductName</p>
                                                }
                                                @{
                                                var readPrice = "";
                                                if (item.SpecialPrice > 0)
                                                {
                                                    if (Parameters.ShowPricesWithoutTax)
                                                    {
                                                        readPrice = item.SpecialPriceWithOutTax.ToString("###,###,##0.00") + " " + item.Currency;
                                                    }
                                                    else
                                                    {
                                                        readPrice = item.SpecialPrice.ToString("###,###,##0.00") + " " + item.Currency;
                                                    }
                                                }
                                                else
                                                {
                                                    if (Parameters.ShowPricesWithoutTax)
                                                    {
                                                        readPrice = item.PriceWithOutTax.ToString("###,###,##0.00") + " " + item.Currency;
                                                    }
                                                    else
                                                    {
                                                        readPrice = item.Price.ToString("###,###,##0.00") + " " + item.Currency;
                                                    }
                                                }                                       
                                                }
                                                <p class="product-price">@readPrice @{if (relPosition != "bottomright")
                                                                                      {<span>KDV Dahil</span>}}
                                                </p>
                                            </a>
                                            <div class="clearfix"></div>
                                        </div>
                                    </div>
                                </li>
                                                                                      relatedProductCount++;
                            }

                        </ul>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="special-products-title">@ViewBag.PartialTitle</div>
    </div>
    }
}